/*
 * @Author: Troubadour 2276791354@qq.com
 * @Date: 2024-08-10 23:29:50
 * @LastEditors: Troubadour 2276791354@qq.com
 * @LastEditTime: 2024-08-11 00:30:08
 * @Version:
 * @Description:
 */

#ifndef __KEYSW_H__
#define __KEYSW_H__

/*-------------------------------------------------------------------------------------------------------------------------------------
-                                                  Include file                                                                       -
--------------------------------------------------------------------------------------------------------------------------------------*/

#include <stdint.h>
#include <main.h>
/*-------------------------------------------------------------------------------------------------------------------------------------
-                                                  External macro                                                                     -
--------------------------------------------------------------------------------------------------------------------------------------*/

#define KEYSW_SCANF_PERIOD_MS           (10U)
#define KEYSW_Read_Pin(GPIOx, Pin)      (HAL_GPIO_ReadPin(GPIOx, Pin))
/*-------------------------------------------------------------------------------------------------------------------------------------
-                                                  External enum                                                                      -
--------------------------------------------------------------------------------------------------------------------------------------*/

typedef enum
{
    KEYSW_UP_ID = 0U,
    KEYSW_DOWN_ID,
    KEYSW_TOUCH_ID,
    KEYSW_STATE_MAX
} KeySw_ID_TypeDef;
/*-------------------------------------------------------------------------------------------------------------------------------------
-                                                  External structure                                                                 -
--------------------------------------------------------------------------------------------------------------------------------------*/

typedef struct
{
    KeySw_ID_TypeDef id;
    GPIO_TypeDef *GPIOx;
    uint16_t GPIO_Pin;
    uint8_t state;
    uint16_t filter_cnt;
    uint16_t filter_threshold;
    uint8_t trigger;
} KeySw_TypeDef;
/*-------------------------------------------------------------------------------------------------------------------------------------
-                                                  External variables                                                                 -
--------------------------------------------------------------------------------------------------------------------------------------*/


/*-------------------------------------------------------------------------------------------------------------------------------------
-                                                  External function                                                                  -
--------------------------------------------------------------------------------------------------------------------------------------*/

uint8_t KeySw_GetPin(KeySw_ID_TypeDef Pin_ID);
uint8_t KeySw_GetTrigger(KeySw_ID_TypeDef *Pin_ID, uint8_t clear_trigger);
void KeySw_Scanf_Task(void);


#endif  /* __KEYSW_H__ */
